#include <string>
#include <cctype>
#include <iostream>

using namespace std;

class Solution {
public:
    int StrToInt(string str) {
        bool flag = false;
        int count = 0;
        if (str[0] == '+' || str[0] == '-' || isdigit(str[0])){
            if (str[0] == '-'){
                flag = true;
            }
            if (isdigit(str[0])){
                count = count + str[0] - '0';
                
            }
        }
        else{
            return 0;
        }

        for (int i = 1; i < str.size(); i++){
            count *= 10;
            if (isdigit(str[i])){
                count += str[i] - '0';
            }
            else{
                return 0;
            }
        }
        if (flag){
            count = -count;
        }
        return count;
    }
};

